// app.js
import './utils/extend-api/AKHttp'

App({
  globalData: {},
  onLaunch: function () {
    // 记录屏幕尺寸比例
    this.setPageScale()
    // 记录屏幕胶囊数据
    this.getMenuButtonRect()
  },

  // ===============  适配尺寸方法  ===============
  // 注入: 屏幕尺寸比例(当前页面对象)
  addSreenSize(that) {
    that.setData({
      pageScale: this.globalData.pageScale
    })
  },
  // 注入: 屏幕胶囊数据(当前页面对象)
  addMenuButtonRect(that) {
    const {
      boundingClientBottom,
      boundingClientHeight,
      safeTop
    } = this.globalData
    that.setData({
      boundingClientBottom,
      boundingClientHeight,
      safeTop
    })
  },
  // 记录屏幕尺寸比例
  getPageScale() {
    return this.globalData.pageScale
  },
  // 记录屏幕尺寸比例
  setPageScale() {
    const {
      windowWidth,
      windowHeight
    } = wx.getWindowInfo()
    this.globalData.pageScale = windowWidth / 375
    this.globalData.screenHeight = windowHeight
    this.globalData.screenWidth = windowWidth
  },
  // 记录屏幕胶囊数据
  getMenuButtonRect() {
    let {
      height,
      top
    } = wx.getMenuButtonBoundingClientRect()
    console.log('getMenuButtonBoundingClientRect', wx.getMenuButtonBoundingClientRect())
    //计算出胶囊底部距离
    const boundingClientBottom = top + height + 8
    this.globalData.boundingClientBottom = boundingClientBottom
    this.globalData.boundingClientHeight = height
    this.globalData.safeTop = top
  }
});